package fr.inserm.u915.organifooyi.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


@Entity(name="user")
@Table(name="user")
@NamedQueries({
    @NamedQuery(name="user.list.all",
            query="select u from user as u order by u.login"),
    @NamedQuery(name="user.find.by.login",
                query="select u from user as u where u.login=:login")
})
public class User
	{
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY, generator="native")
	private Long id;
	
	@Column(name="name")
	private String name;
	@Column(name="md5password")
	private String md5password;
	@Column(name="login")
	private String login;
	
	@OneToMany(mappedBy="user",fetch=FetchType.LAZY,cascade=CascadeType.PERSIST)
	private List<UserRole> roles=new java.util.ArrayList<UserRole>();
	
	
	public String getMd5password()
		{
		return md5password;
		}	


	public void setMd5password(String md5password)
		{
		this.md5password = md5password;
		}

	public Long getId() {
		return id;
	}



	protected void setId(Long id) {
		this.id = id;
	}



	public String getName() {
		return name;
	}



	public void setName(String name) {
		this.name = name;
	}



	public String getLogin() {
		return login;
	}



	public void setLogin(String login) {
		this.login = login;
	}

	public List<UserRole> getRoles()
		{
		return roles;
		}
	
	public void setRoles(List<UserRole> roles)
		{
		this.roles = roles;
		}

	@Override
	public String toString()
		{
		return name+" ("+id+")";
		}
	}
